//
//  WeekDetailViewController.m
//  hospitalVIP
//
//  Created by xiaoyan on 14-1-7.
//  Copyright (c) 2014年 MEETStudio. All rights reserved.
//

#import "WeekDetailViewController.h"

@interface WeekDetailViewController ()
{
    ASIHTTPConnection *weekTips_connect;
}
@end

@implementation WeekDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)dealloc{
    
    [scrollView release];
    scrollView = nil;
    
    if (weekTips_connect != nil) {
        weekTips_connect.connectionDelegate = nil;
        [weekTips_connect release];
        weekTips_connect = nil;
    }
    
    [title1 release];
    title1 = nil;
    
    [content1 release];
    content1 = nil;
    
    [imageview1 release];
    imageview1 = nil;
    
    [super dealloc];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSString *path = [[NSBundle mainBundle] pathForResource:@"bg_pattern_wood" ofType:@"png"];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:path]];

    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    scrollView.scrollEnabled = YES;
    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, 580)];
    
    [self setTItleWith:@"孕周知识"];
    
    
    //ios7 优化
    
    if( iOS7) {
        
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.navigationController.navigationBar.translucent = NO;
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
        [scrollView setContentInset:UIEdgeInsetsMake(40, 0, 0, 0)];
        
    }
    else{
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
    }
    
    
    UIButton *leftBt = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    [leftBt setImage:[UIImage imageNamed:@"icon_return.png"] forState:UIControlStateNormal];
    [leftBt addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:leftBt];
    [self.navigationItem setLeftBarButtonItem:leftButton];
    [leftBt release];
    [leftButton release];
    
    [self loadData];
}


- (void)loadData{
    
    
    NSString *urlString = [NSString stringWithFormat:@"http://211.83.105.71:3306/MonitorSystem_V1.0/Mobile/week_weekknowledge?weekid=%d",1];
	NSURL *url = [NSURL URLWithString:urlString];
    
    if (weekTips_connect != nil) {
        weekTips_connect.connectionDelegate = nil;
        [weekTips_connect release];
        weekTips_connect = nil;
    }
    
    
    weekTips_connect = [[ASIHTTPConnection alloc] initGETWithURL:url resultDict:YES isCache:YES];
    weekTips_connect.connectionDelegate = self;
    
    [weekTips_connect startAsynchronous];
    
}


- (void)requestFailed:(ASIHTTPConnection *)connection error:(NSError *)error URL:(NSURL *)url info:(NSDictionary *)info{
    
}

- (void)requestFinished:(ASIHTTPConnection *)connection resultDict:(NSDictionary *)dict URL:(NSURL *)url info:(NSDictionary *)info{
    
    CLog(@"week tips dict %@",dict);
    
    
    
}

- (void)backAction:(id)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setTItleWith:(NSString *)title{
    
    UILabel *titleView = (UILabel *)self.navigationItem.titleView;
    if (!titleView) {
        titleView = [[UILabel alloc] initWithFrame:CGRectZero];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.font = [UIFont systemFontOfSize:20.0];
        
        titleView.textColor = [UIColor whiteColor]; // Change to desired color
        
        self.navigationItem.titleView = titleView;
        [titleView release];
    }
    titleView.text = title;
    [titleView sizeToFit];
    
    
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
